<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>移动办公自动化系统</title>
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/base.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/info-mgt.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/WdatePicker.css" />

		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/common.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/WdatePicker.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.pagination.js"></script>
	</head>

	<body onload="select()">
		<div class="title">
			<h2>
				公共资源信息管理
			</h2>
		</div>
		<form method="post"
			action="${pageContext.request.contextPath }/ComMethod.action?method=selectCom"
			method="post">
			<div class="query">
				<div class="query-conditions ue-clear">
					<div class="conditions name ue-clear">
						<label>
							物品名称：
						</label>
						<p class="long-input ue-clear">
							<input type="text" name="name" id="name"
								value="${requestScope.select.name }" />
						</p>
					</div>
					<div class="conditions operate-time ue-clear">
						<label>
							金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额：
						</label>
						<input type="text" name="minprice" id="minprice"
							value="${requestScope.select.minprice<=0?'':requestScope.select.minprice }" />
						-
						<input type="text" name="maxprice" id="maxprice"
							value="${requestScope.select.maxprice<=0?'':requestScope.select.maxprice }" />

					</div>
					<div class="conditions time ue-clear">
						<label>
							数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量：
						</label>
						<input type="text" name="minnum" id="minnum"
							value="${requestScope.select.minnum<=0?'':requestScope.select.minnum }" />
						-
						<input type="text" name="maxnum" id="maxnum"
							value="${requestScope.select.maxnum<=0?'':requestScope.select.maxnum }" />
					</div>
					<div class="query-conditions ue-clear">
						<label>
							状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态：
						</label>
						<input type="radio" name="status" value="fine" class="status1"
							checked="checked" id="status">
						正常
						<input type="radio" name="status" value="unfine" class="status2"
							id="status" />
						维护
					</div>
					<div class="conditions name ue-clear">
						<label>
							物品类型：
						</label>
						<p class="long-input ue-clear">
							<select id="comtype" name="comtype">
								<option>请选择</option>
								<option>办公用品</option>
								<option>公共资源</option>
							</select>
						</p>
					</div>   
				</div>
				<div class="query-btn ue-clear">
					<input type="submit" id="submit" value="查询" />
					<input type="button" id="reset" value="重置" onclick="reset()">
				</div>
			</div>
			<div class="table-operate ue-clear">
				<a
					href="${pageContext.request.contextPath }/mhm/ComResource/AddCom.jsp"
					class="add">添加</a>
				 <a href="${pageContext.request.contextPath }/ComMethod.action?method=selectAppCom"
				 	class="check">审核</a>
				 <a href="${pageContext.request.contextPath }/ComMethod.action?method=selectApplyNeedReturn" class="edit">归还</a>
			</div>


			<div class="table-box">
				<table>
					<thead>
						<tr>
							<th class="num">
								序号
							</th>
							<th class="name">
								物品名称
							</th>
							<th>
								物品类型
							</th>
							<th class="process">
								价格
							</th>
							<th class="node">
								状态
							</th>
							<th class="time">
								数量
							</th>
							<th class="time">
								剩余数量
							</th>
							<th class="operate">
								操作
							</th>
						</tr>
					</thead>
					<c:forEach items="${requestScope.comlist.data}" var="comlist"
						varStatus="c">
						<tbody>
							<tr>
								<td class="num">
									${comlist.crId }
								</td>
								<td class="name">
									${comlist.crName }
								</td>
								<td>
									${comlist.crType }
								</td>
								<td class="process">
									${comlist.crPrice }
								</td>
								<td class="node">
									${comlist.crCondition }
								</td>
								<td class="time">
									${comlist.crNum }
								</td>
								<td class="time">
									${comlist.crOverplus }
								</td>
								<td class="operate">

									<label style="cursor: pointer; color: blue"
										onclick="toupdateCom('${comlist.crId}','${requestScope.comlist.currentPage}')">
										编辑
									</label>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<label style="cursor: pointer; color: blue"
										onclick="deleteCom('${comlist.crId}','${requestScope.comlist.currentPage}')">
										删除
									</label>
								</td>
							</tr>
						</tbody>
					</c:forEach>
				</table>
			</div>
			<div>
				<table width="80%" align="center" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<a onclick=skipPage('1');;>首页</a>
						</td>
						<td>
							<a
								onclick="skipPage('${requestScope.comlist.currentPage==1?1:requestScope.comlist.currentPage-1 }');">上一页</a>
						</td>
						<td>
							<a
								onclick="skipPage('${requestScope.comlist.currentPage==requestScope.comlist.totalPage?(requestScope.comlist.currentPage):(requestScope.comlist.currentPage+1) }');">下一页</a>
						</td>
						<td>
							<a onclick="skipPage('${requestScope.comlist.totalPage}');">末页</a>
						</td>
						<td>
							当前页码：${requestScope.comlist.currentPage}/${requestScope.comlist.totalPage}
						</td>
					</tr>
				</table>
			</div>
		</form>
	</body>
	<script type="text/javascript">
	window.onload=function(){
		if('${requestScope.opop}'=='1'){
			alert("除数量外修改成功，数量请等待审批");
		}else if('${requestScope.opop}'=='0'){
			alert("修改成功");
		}
		
		if('${requestScope.delete}'=='1'){
			alert("删除成功");
		}else if('${requestScope.delete}'=='0'){
			alert("当前物品存在待审批或未归还信息，请拒绝申请或归还物品后操作")
		}
		
		$("#comtype option").each(function() {
			if($(this).val()=='${requestScope.select.comtype}'){
				$(this).attr('selected',true);
			}
		});
	}
	$('#reset').click(function(){
		$("#name").val("");
		$("#minprice").val("");
		$("#maxprice").val("");
		$("#maxnum").val("");
		$("#minnum").val("");
		$('.status1').attr('checked', 'checked');
	})
	
	
	
	function toupdateCom(id,currentPage) {

		var url = '${pageContext.request.contextPath }/ComMethod.action?method=toupdateCom&crId=' + id;
		url += '&currPage=' + currentPage;
		url += '&name=' + document.getElementById("name").value;
		url += '&minprice=' + document.getElementById("minprice").value;
		url += '&maxprice=' + document.getElementById("maxprice").value;
		url += '&maxnum=' + document.getElementById("maxnum").value;
		url += '&minnum=' + document.getElementById("minnum").value;
		url += '&status=' + document.getElementById("status").value;
		window.location.href = url;
	}
	function deleteCom(crId, currentPage) {
		var a = confirm("确认删除?");
		var url = '${pageContext.request.contextPath }/ComMethod.action?method=deleteCom&crId=' + crId;
		url += '&currPage=' + currentPage;
		url += '&name=' + document.getElementById("name").value;
		url += '&minprice=' + document.getElementById("minprice").value;
		url += '&maxprice=' + document.getElementById("maxprice").value;
		url += '&maxnum=' + document.getElementById("maxnum").value;
		url += '&minnum=' + document.getElementById("minnum").value;
		url += '&status=' + document.getElementById("status").value;
		if (a) {
			window.location.href = url;
		} else {
			return false;
		}
	}
	function skipPage(currentPage) {
		var url = '${pageContext.request.contextPath }/ComMethod.action?method=selectCom&currPage=' + currentPage;
		url += '&name=' + document.getElementById("name").value;
		url += '&minprice=' + document.getElementById("minprice").value;
		url += '&maxprice=' + document.getElementById("maxprice").value;
		url += '&maxnum=' + document.getElementById("maxnum").value;
		url += '&minnum=' + document.getElementById("minnum").value;
		url += '&status=' + document.getElementById("status").value;

		window.location.href = url;
	}
</script>
</html>
